package com.ctshk.app.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.tour.dto.*;
import com.ctshk.rpc.tour.dto.cache.TripGroup;
import com.ctshk.rpc.tour.dto.cache.TripSearchResDTO;
import com.ctshk.rpc.tour.dto.schedule.SeriesTripGroupDTO;
import com.ctshk.rpc.tour.req.FavoritesReq;
import com.ctshk.rpc.tour.req.LocalHotSearchReq;
import com.ctshk.rpc.tour.req.es.TripSearchReq;
import com.ctshk.rpc.tour.service.ISeriesTripAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系列团行程 PC前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-12
 */
@Api(value = "旅行团-APP-PC端", tags = "旅行团-APP-PC端")
@RestController
@RequestMapping("/series/trip")
public class SeriesTripController extends BaseController {

    @DubboReference
    private ISeriesTripAppService iSeriesTripAppService;

    @ApiOperation(value = "旅行团首页-关联搜索", notes = "旅行团首页-关联搜索")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团首页-关联搜索", operDesc = "旅行团首页-关联搜索")
    @PostMapping("/search-association/{key}")
    public Result<List<DestinationDTO>> associationSearch(@PathVariable("key") String key) {
        return Result.success(iSeriesTripAppService.associationSearch(key));
    }

    @ApiOperation(value = "旅行团首页-三级分类&banner&公告", notes = "旅行团首页-三级分类")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团首页-三级分类", operDesc = "旅行团首页-三级分类")
    @GetMapping("/home/catalog")
    public Result<TourPcHomeCatalogAndCmsDTO> getCatalogInfo() {
        return iSeriesTripAppService.getTripHomeCatalogAndBannerAndNotic();
    }

    @ApiOperation(value = "旅行团首页—旅游分组", notes = "旅行团首页-旅游分组")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团首页-旅游分组", operDesc = "旅行团首页-旅游分组")
    @GetMapping("/home/group/{channelId}")
    public Result<List<SeriesTripGroupDTO>> tripGroupInfo(@PathVariable("channelId") Long channelId) {
        return Result.success(iSeriesTripAppService.getHomeGroupInfo(channelId));
    }

    @ApiOperation(value = "旅行团首页—当季热卖", notes = "旅行团首页-当季热卖")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团首页-当季热卖", operDesc = "旅行团首页-当季热卖")
    @PostMapping("/home/hot/{channelId}")
    public Result<List<TripGroup>> tripHotInfo(@PathVariable("channelId") Long channelId) {
        return Result.success(iSeriesTripAppService.getHotGroupInfo(new LocalHotSearchReq().setChannelId(channelId).setSize(4)));
    }

    @ApiOperation(value = "旅行团详情", notes = "旅行团详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团详情", operDesc = "旅行团详情")
    @GetMapping("/details/{id}/{channelId}")
    public Result<TripDetailsResDTO> getTripSearch(@PathVariable("id") Long id, @PathVariable("channelId") Long channelId) {
        return iSeriesTripAppService.getPCTripDetails(id, channelId, getCurrentUserAllowNotLogInUserId());
    }

    @ApiOperation(value = "旅行团-搜索", notes = "旅行团-搜索")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团-搜索", operDesc = "旅行团-搜索")
    @PostMapping("/search")
    public Result<TripSearchResDTO> getTripSearch(@RequestBody @Valid TripSearchReq tripSearchReq) {
        return Result.success(iSeriesTripAppService.getTripsByParams(tripSearchReq));
    }

    @ApiOperation(value = "旅行团-详情-收藏", notes = "旅行团-详情-收藏")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.ADD, operTitle = "旅行团-详情-收藏", operDesc = "旅行团-详情-收藏")
    @PostMapping("/favorites")
    public Result favorites(@RequestBody @Valid FavoritesReq req) {
        TokenUser user = getCurrentUser();
        return Result.success(iSeriesTripAppService.favorites(req, user));
    }

/*
    @ApiOperation(value = "旅行团详情-查看出发日期&价格", notes = "旅行团详情-备注")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团详情-备注", operDesc = "旅行团详情-备注")
    @PostMapping("/details/date-price")
    public Result<TripScheduleItineraryDayDTO> dateAndPrice(@RequestBody @Valid TripDetailsReq req) {
        return iSeriesTripAppService.dateAndPrice(req);
    }
*/

}
